package com.zhangsun.yueBoot.admin.user.controller;

import com.zhangsun.yueBoot.admin.user.entity.RegisterUser;
import com.zhangsun.yueBoot.admin.user.service.UserService;
import com.zhangsun.yueBoot.commons.base.bean.ResponseResult;
import com.zhangsun.yueBoot.commons.base.controller.BaseController;
import com.zhangsun.yueBoot.framework.expection.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户
 */
@RestController
@Api(value = "用户接口", tags = {"用户接口"})
@RequestMapping("/system/user")
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 注册用户
     *
     * @param registerUser 注册信息
     * @return 结果
     * @throws BusinessException 异常
     */
    @ApiOperation(value = "注册用户", notes = "注册用户")
    @PostMapping("/register")
    public ResponseResult register(@Validated RegisterUser registerUser) throws BusinessException {
        userService.register(registerUser);
        return ResponseResult.success("注册成功");
    }

    /**
     * 重置admin密码
     *
     * @return 结果
     */
    @ApiOperation(value = "重置admin密码", notes = "重置admin密码")
    @PostMapping("/resetAdmin")
    public ResponseResult resetAdmin() {
        userService.resetAdmin();
        return ResponseResult.success("重置成功");
    }

}
